//
//  GGMatchesVC.swift
//  DongBaoDemo
//
//  Created by 陈志勇 on 2018/8/4.
//  Copyright © 2018年 陈志勇. All rights reserved.
//

import UIKit

class GGMatchesVC: GGBaseTableVC {

    var raceList: [Race] = [] {
        didSet {
            tableView.reloadData()
        }
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()

        tableView.register(UINib.init(nibName: "GGMatchesActivityCell", bundle: nil), forCellReuseIdentifier: "GGMatchesActivityCell")
        
        reqtuestRaceList()
    }

}

extension GGMatchesVC {
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return raceList.count
    }
    
    override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 200
    }
    
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "GGMatchesActivityCell", for: indexPath) as! GGMatchesActivityCell
        cell.race = raceList[indexPath.row]
        return cell
    }
    
}

// MARK: - 网络请求
extension GGMatchesVC {
    func reqtuestRaceList() {
        NetWorkTool.shared.loadRaceList { (response) in
            
            
            guard let raceInfo = ResponseInfo<Race>.deserialize(from: response.data?.info) else {
                return
            }
            
            guard let list = raceInfo.race_list?.list else {
                return
            }
            
            self.raceList = list
        }
    }
}


